package com.raven.craft.code.generator.mysql.sql;

import com.raven.craft.code.generator.IGenerator;
import com.raven.craft.code.generator.common.constant.FileSuffix;
import com.raven.craft.code.generator.common.file.HbsFile;
import com.raven.craft.code.generator.common.file.metadata.FileMetadata;
import com.raven.craft.code.generator.config.MysqlContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SqlGenerator implements IGenerator {

    private final MysqlContext context;
    private final SqlProperties properties;

    public SqlGenerator(MysqlContext context, SqlProperties properties) {
        this.context = context;
        this.properties = properties;
    }

    private static HbsFile createSqlFile(MysqlContext context, SqlProperties properties) {
        FileMetadata metadata = new FileMetadata(context.getDatabase(), FileSuffix.SQL, properties.getTargetDir());
        SqlVo vo = new SqlVo(context);
        return new HbsFile(metadata, properties.getTemplatePath(), vo);
    }

    @Override
    public void generate() {
        log.info("begin to generate sql file");
        createSqlFile(context, properties).output();
    }
}
